home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7369 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  48 lines

  1. Path: howland.reston.ans.net!usc!usc!not-for-mail
  2. From: wawda@alcor.usc.edu (Abu Wawda)
  3. Newsgroups: comp.lang.c
  4. Subject: What is &Variable (declared as: char Variable[10])?
  5. Date: 25 Feb 1996 14:53:53 -0800
  6. Organization: University of Southern California, Los Angeles, CA
  7. Sender: wawda@alcor.usc.edu
  8. Distribution: world
  9. Message-ID: <4gqpa1$3h9@alcor.usc.edu>
  10. NNTP-Posting-Host: alcor.usc.edu
  11.  
  12. I'm having trouble understanding what the address of a static array
  13. is. For example, if I declare a variable called myarray as:
  14.     char myarray[10];
  15. then what could &myarray possibly mean? myarray is not a pointer, so
  16. &myarray could not possibly be the address of the variable myarray
  17. (like it would be if I did char* myarray and then asked for &myarray).
  18.  
  19. Functions such as scanf() allow the following:
  20.  
  21.     char myarray[10];
  22.  
  23.     scanf("%s",&myarray);
  24.  
  25. but I don't understand what scanf() could possibly be taking in the
  26. second parameter. It can't be: char** since myarray is not a
  27. pointer. I CAN understand how the following would work:
  28.  
  29.     char* myarray;
  30.  
  31.     myarray = (char*) malloc(10);
  32.     scanf("%s",&myarray);
  33.  
  34. Then scanf() is simply taking a char** (pointer to a character
  35. pointer, or in other words the address of the pointer myarray) in its
  36. second paremeter. However, if I write my own function like this:
  37.  
  38.     void func(char** p)
  39.     {
  40.         // do something here
  41.     }    
  42.  
  43. I cannot pass &myarray if I declare it as: char myarray[10]. So how do
  44. this work? Thanks in advance,
  45.  
  46. Abu Wawda
  47. wawda@scf.usc.edu
  48.